'''
Created on Mar 25, 2013

@author: LONG HOANG GIANG
'''
import os
import gzip as _gzip

def file_get_content(filepath):
    if os.path.isfile(filepath):
        fp = open(filepath, 'rb')
        data = fp.read()
        fp.close()
        return data
    return None

def file_put_content(filepath, data):
    parent = os.path.dirname(filepath)
    if parent in ['', '.']: return
    if not os.path.isdir(parent): os.makedirs(parent, 0777)
    fp = open(filepath, 'wb')
    fp.write(data)
    fp.close()
    
def gz_file_put_content(filepath, data):
    parent = os.path.dirname(filepath)
    if parent in ['', '.']: return
    if not os.path.isdir(parent): os.makedirs(parent, 0777)
    fp = _gzip.open(filepath, 'wb')
    fp.write(data)
    fp.close()
    
def gz_file_get_content(filepath):
    if os.path.isfile(filepath):
        fp = _gzip.open(filepath, 'rb')
        data = fp.read()
        fp.close()
        return data
    return None